﻿﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dbPoll_Application.ViewModels.ParticipantFieldViewModel>" %>

<p><label for="addgroup">Add Group:</label> <input name="addgroup" type="text" id="addgroup"/>
<button id="addstuff" onclick="addGroup()">Add</button></p>
<div style="overflow:auto;max-height:600px">
<table class="editParticipant" style="overflow:auto">
    <thead>
        <tr id="headering">
        <th>Group</th>
            <% int i = 0;
                foreach (var field in Model.poll.participantFields)
               {%>
            <th id="<%=field.fieldID %>">
            <input type="hidden" id="dem<%=field.fieldID%>" value="<%=Model.hasdem[i]%>"/>
               <input type="hidden" id="com<%=field.fieldID%>" value="<%=Model.hascom[i]%>"/>
                <%=field.name%><br /><button onclick="deleting(<%=field.fieldID %>)">Delete</button>
            </th><%
            i++;
            } %><th>Entity</th>
        </tr>
    </thead>
    <tbody>
        <% 
            foreach (var participant in Model.fieldValues)
           {
               i = 0; 
        %>
        <tr id="<%=participant["groupID"]%>">
            <%  foreach (var field in participant)
                {
                    if (field.Key.Equals("Name"))
                    {%> <td><%= Html.ActionLink(field.Value, "Details", "Participant", new { participantID = participant.ElementAt(0).Value, pollID = Model.poll.pollID }, null)%></td>
                    <%}
                    else if (!field.Key.Equals("groupID") && !field.Key.Equals("Entity"))
                    {%><td><input type="text" ID="TextBox1" size=10 name= "<%=field.Value%>" value="<%=field.Value%>"></input></td>
                    <%}
                    i++;
                   
                }%><td><select name="<%=participant["Entity"]%>"><%foreach (var entity in Model.entities) 
                                 { %><option <% if (participant["Entity"].Equals(entity.name)) { %> selected="selected" <% } %> value="<%=entity.entityID %>" ><%=entity.name %></option><%} %></select></td>
        </tr>
        <%} %>
    </tbody>
</table>
</div>